<style>
#report_table {margin:0px auto; font-size:13px;}
#report_table tr td, #report_table tr th {text-align:center; padding:5px 10px;}
#report_table tr th {color:#e17009}
#report_table tbody tr:nth-child(odd) td {background-color: #f0f0f0;}
</style>
<h2 style="text-align:center"><u>Sales Report</u></h3>
<?if($title):?>
	<h5 style="text-align:center"><?=$title?></h3>
<?endif;?>
<table id="report_table" style="width:90%;">
	<tr>
		<th>Item</th>
		<th width="80px">Quantity</th>
		<th>WSP</th>
		<th>RP</th>
		<th>Total Sale</th>
		<th>Total Profit</th>
		<th>Total Disc</th>
	</tr>
	<tbody>
	<?if($item_total_sold->num_rows()):?>
		<?$total_sale=0;$total_profit=0;$total_loss=0;$total_wsp=0;$total_rp=0?>
		<?foreach($item_total_sold->result() as $item):?>
			<?if($item->total_quantity):?>
				<tr>
					<td><?=$item->item_name?></td>
					<td><?=$item->total_quantity ? $item->total_quantity : '0'?></td>
					<td>P <?=number_format($item->item_whole_sale_price,2,'.',',')?></td>
					<td>P <?=number_format($item->item_retail_price,2,'.',',')?>
					<td>P <?=number_format($item->item_sales_total,2,'.',',')?></td>
					<td>P <?=number_format(($item->item_retail_price-$item->item_whole_sale_price)*$item->total_quantity,2,'.',',')?></td>
					<td>P <?=number_format($item->sale_item_discount_price,2,'.',',')?></td>
				</tr>
				<?$total_rp = $total_rp + $item->item_retail_price;?>
				<?$total_wsp = $total_wsp + $item->item_whole_sale_price;?>
				<?$total_profit = $total_profit + (($item->item_retail_price-$item->item_whole_sale_price)*$item->total_quantity)?>
				<?$total_sale = $total_sale + $item->item_sales_total;?>
				<?$total_loss = $total_loss + $item->sale_item_discount_price;?>
			<?endif;?>
		<?endforeach;?>
		<?if($total_sale):?>
			<tr>
				<td colspan="2" style="text-align:right">Total:</td>
				<td>P <?=number_format($total_wsp,2,'.',',')?></td>
				<td>P <?=number_format($total_rp,2,'.',',')?></td>
				<td>P <?=number_format($total_sale,2,'.',',')?></td>
				<td>P <?=number_format($total_profit,2,'.',',')?></td>
				<td>P <?=number_format($total_loss,2,'.',',')?></td>
			</tr>
		<?else:?>
			<tr>
				<td colspan="7">No Recent Sale.</td>
			</tr>
		<?endif;?>
	<?else:?>
		<tr>
			<td colspan="7">No Recent Sale.</td>
		</tr>
	<?endif;?>
	</tbody>
</table>